<template>
  <div v-loading="loading" class="app-container">
    <el-form ref="queryForm" :model="queryParams" :inline="true" label-width="68px">
      <el-form-item label="商户公司" prop="orderId">
        <el-input
          v-model="queryParams.merchant_name"
          placeholder="请输入商户公司名称"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!--    <el-row :gutter="10" class="mb8">-->
    <!--      <el-col :span="1.5">-->
    <!--        <el-button-->
    <!--          type="primary"-->
    <!--          plain-->
    <!--          icon="el-icon-plus"-->
    <!--          size="mini"-->
    <!--          @click="handleCreate"-->
    <!--        >创建商户</el-button>-->
    <!--      </el-col>-->
    <!--    </el-row>-->

    <el-table :data="list" style="width: 100%;">
      <el-table-column label="商户名称" align="center" prop="merchant_name" />
      <el-table-column label="商户号" align="center" prop="merchant_id" />
      <el-table-column label="秘钥" align="center" prop="secret" />
      <el-table-column label="入驻时间" align="center" prop="create_time" />
      <!--      <el-table-column label="关联平台" align="center" prop="tenant_id" />-->
      <el-table-column label="启用状态" align="center" prop="status" />
      <!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
      <!--        <template v-slot="scope">-->
      <!--          <el-button-->
      <!--            size="mini"-->
      <!--            type="primary"-->
      <!--            @click="openDetail(scope.row.task_no)"-->
      <!--          >订单操作</el-button>-->
      <!--          <el-button-->
      <!--            size="mini"-->
      <!--            type="danger"-->
      <!--            :disabled="scope.row.status === 0 ? false : true"-->
      <!--            @click="cancelTask(scope.row.task_no)"-->
      <!--          >撤销</el-button>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--    </el-table>-->
      <pagination v-show="total>0" :total="total" :page.sync="queryParams.page" :limit.sync="queryParams.limit" @pagination="getList" />
    </el-table>
    <!-- 修改进度 -->
    <el-dialog title="创建商户" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="addInfo" label-width="100px">
        <el-form-item label="企业全称" prop="status" :span="8">
          商户类别
          <el-tooltip content="公司注册全称" placement="top">
            <i class="el-icon-info" />
          </el-tooltip>
          <el-input v-model="addInfo.warehouse" placeholder="请填写企业全称" />
        </el-form-item>
        <el-form-item label="商户类别" prop="status">
          <span slot="label">
            商户类别
            <el-tooltip content="后台管理类别包括可作为后台管理和对外接口的商户，对外接口则仅能供商户对外接口使用" placement="top">
              <i class="el-icon-info" />
            </el-tooltip>

          </span>
          <el-select v-model="addInfo.warehouse" placeholder="请选择商户类别">
            <el-option
              v-for="(item, index) in options"
              :key="index"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="addTask">提 交</el-button>
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { list } from '@/api/tenant'
export default {
  name: 'Index',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      open: false,
      row: undefined,
      addInfo: {},
      // 表格数据
      list: [],
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        page: 1,
        limit: 10,
        merchant_name: undefined
      },
      options: [
        { label: '后台管理', value: 1 },
        { label: '对外接口', value: 2 }
      ],
      ids: []
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询订单列表 */
    getList() {
      this.loading = true
      list(this.queryParams).then(response => {
        if (response.code === 10000) {
          this.list = response.data
          this.total = response.count
          this.loading = false
        }
      })
    },
    /** 打开 */
    handleCreate(row) {
      this.addInfo = {}
      this.open = true
    },
    /** 关闭 */
    cancel() {
      this.open = false
      this.addInfo = {}
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.queryParams = {
        page: 1,
        limit: 10,
        merchant_name: undefined
      }
      this.handleQuery()
    },
    /** 提交时间改变 */
    datePick(value) {
      if (value) {
        this.queryParams.start_time = value[0]
        this.queryParams.end_time = value[1]
      } else {
        this.queryParams.start_time = undefined
        this.queryParams.end_time = undefined
      }
    }
  }
}
</script>
